﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Samples.ServiceHosting.StorageClient;

namespace Astoman.Common.Repository
{
    public class QueueRepository : IBaseRepository
    {
        QueueStorage qs = null;

        public QueueRepository(StorageAccountInfo accountInfo)
        {
            qs = QueueStorage.Create(accountInfo);
        }

        public List<string> List()
        {
            var queues = qs.ListQueues();
            return (from queue in queues
                   select queue.Name).ToList();
        }

        public bool Delete(string storageItem)
        {
            throw new NotImplementedException();
        }

        public IEnumerable<Message> GetMessagesInQueue(String queueName)
        {
            var queue = qs.GetQueue(queueName);
            return from message in queue.PeekMessages(20)
                   select message;
        }

        public QueueProperties GetQueueProperties(String queueName)
        {
            var queue = qs.GetQueue(queueName);
            return queue.GetProperties();
        }

        public int Count()
        {
            var queues = qs.ListQueues();
            return queues.Count();
        }
    }
}
